//
//  UIViewAnimationController.m
//  CoreAnimationDemo
//
//  Created by AY on 17/5/31.
//  Copyright © 2017年 Alex. All rights reserved.
//

#import "UIViewAnimationController.h"

@interface UIViewAnimationController ()
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@property (weak, nonatomic) IBOutlet UIView *yellowView;
@property (nonatomic) int index;
@end

@implementation UIViewAnimationController

- (instancetype)init {
    self = [super init];
    if (self) {
        self = [self initWithNibName:NSStringFromClass([UIViewAnimationController class]) bundle:nil];
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
}

/// 简单动画
- (void)viewSimpleAnimation {
//    [UIView beginAnimations:nil context:nil];
//    self.yellowView.center = CGPointMake(200, 200);
//    [UIView commitAnimations];

    [UIView animateWithDuration:1.0 animations:^{
        self.yellowView.center = CGPointMake(200, 200);
    } completion:^(BOOL finished) {
        NSLog(@"动画执行结束");
    }];
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    self.index++;
    if (self.index == 3) {
        self.index = 0;
    }
    NSString *filename = [NSString stringWithFormat:@"%d.jpg", self.index + 1];
    self.imageView.image = [UIImage imageNamed:filename];
    [UIView transitionWithView:self.view duration:1.0 options:UIViewAnimationOptionTransitionCrossDissolve animations:nil completion:nil];
//    [self viewSimpleAnimation];
}

@end
